package oj0405.oj0405_02;

import java.util.Scanner;

class Node{
    int data;
    Node next;
    public Node(int data){
        this.data = data;
        this.next = null;
    }
}
class LinkQueue{
    Node f,r;
    public LinkQueue(){
        f = new Node(-1);
        r = f;
    }

    public boolean isEmpty(){
        return f == r;
    }

    public void enQueue(int x){
        Node n = new Node(x);
        r.next = n;
        r = n;
        System.out.println("finish");
    }

    public int deQueue(){
        if (isEmpty()){
            System.out.println("Queue is Empty");
            return -1;
        }
        Node p = f.next;
        int x = p.data;
        f.next = p.next;
        if (p.next == null){
            r = f;
        }
        return x;
    }

    public int getFront(){
        if (isEmpty()){
            System.out.println("Queue is Empty");
            return -1;
        }
        return f.next.data;
    }

    public void display(){
        if (isEmpty()){
            System.out.println("Queue is Empty");
            return;
        }
        Node p = f.next;
        while (p != null){
            System.out.print(p.data + ",");
            p = p.next;
        }
    }

    public int getLength(){
        int count = 0;
        Node p = f.next;
        while (p != null){
            count++;
            p = p.next;
        }
        return count;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkQueue linkQueue = new LinkQueue();
        int row = sc.nextInt();
        int y,res;
        for (int i = 0; i < row; i++) {
            int x = sc.nextInt();
            switch (x){
                case 1:
                    y = sc.nextInt();
                    linkQueue.enQueue(y);
                    break;
                case 2:
                    res = linkQueue.deQueue();
                    if (res != -1){
                        System.out.println(res);
                    }
                    break;
                case 3:
                    res = linkQueue.getFront();
                    if (res != -1){
                        System.out.println(res);
                    }
                    break;
                case 4:
                    System.out.println(linkQueue.getLength());
                    break;
                case 5:
                    linkQueue.display();
                    break;
                default:
                    break;
            }
        }
    }
}
